﻿using static CyberU;
using static CyberU.UI;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;

public class General2DUI : MonoBehaviour
{
    public RectTransform rectTransform;
    public float height
    {
        get => rectTransform.sizeDelta.y;
        set
        {
            if (rectTransform.anchorMax.y - rectTransform.anchorMin.y == 1 && 
                rectTransform.pivot.y == 0.5f) // 非stretch垂直方向
            {
                rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, value);
            }
            else
            {
                Debug.LogWarning("Height adjustment is not supported in stretch mode on Y axis.");
            }
        }
    }

    public float width
    {
        get => rectTransform.sizeDelta.x;
        set
        {
            if (rectTransform.anchorMax.x - rectTransform.anchorMin.x == 1 &&
                rectTransform.pivot.x == 0.5f) // 非stretch水平方向
            {
                rectTransform.sizeDelta = new Vector2(value, rectTransform.sizeDelta.y);
            }
            else
            {
                Debug.LogWarning("Width adjustment is not supported in stretch mode on X axis.");
            }
        }
    }

    public Image background
    {
        get
        {
                return AddOrGetComponent<Image>(gameObject);
        }
        set { background=value; }
    }

    public Color backgroundColor
    {
        set { background.color = value; }
        get{return background.color;}
    }
    virtual public  void Initialize()
    {
            rectTransform= AddComponent<RectTransform>(gameObject);
            // SetRoundedCorner(gameObject);
    }
}